Skip to content

Snowflake COPY INTO target columns, select items and optional alias #1805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2025

Conversation

yoavcloud
Copy link
Contributor

This PR adds support for the following in Snowflake's COPY INTO:

  1. Specifying a list of columns in the destination table:
COPY INTO [<namespace>.]<table_name> [ ( <col_name> [ , <col_name> ... ] ) ]
  1. Using regular SQL expressions in the data transformation query, typically for constant or computed values:
SELECT t1.$1:st AS st, $1:index, t2.$1, 4, '5' AS const_str FROM @schema.general_finished
  1. The AS keyword is optional when specifying an alias for the stage in the data transformation query
COPY INTO tbl FROM (SELECT t1.$1:st AS st, 4, '5' AS const_str FROM @stage S)

Comment on lines 881 to 889
match parser.next_token().token {
Token::Comma => {
// continue
}
_ => {
parser.prev_token(); // need to move back
break;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we do something like this in order to avoid the token clone here?

if matches!(parser.peek_token_ref(), Token::Comma) {
    parser.advance()
} else {
   break
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! I included it in the latest commit.

@iffyio iffyio changed the title Snowflake COPY INTO target columns, regular selec items and optional alias Snowflake COPY INTO target columns, select items and optional alias Apr 11, 2025
@yoavcloud yoavcloud requested a review from iffyio April 11, 2025 09:26
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @yoavcloud!
cc @alamb

@iffyio iffyio merged commit d090ad4 into apache:main Apr 11, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants